package services

import (
	"github.com/labstack/gommon/log"
	"law_case_api/dto"
	"law_case_api/models"
)

// CreateContractAccessory 创建客户合同附件信息
func (contract ContractService) CreateContractAccessory(wzjContractAccessory models.WzjContractAccessory) (bool, error) {
	if err := db.Create(&wzjContractAccessory).Error; err != nil {
		log.Error("CreateContractAccessory--创建客户合同附件信息失败,失败原因：", err)
		return false, err
	}
	return true, nil
}

// GetContractAccessoryListByContractId 根据合同信获取附件列表
func (contract ContractService) GetContractAccessoryListByContractId(contractId int) ([]dto.ContractAccessoryResp, error) {
	var wzjContractAccessoryList []dto.ContractAccessoryResp
	sql := `SELECT b.id file_id,b.file_name,b.file_path FROM wzj_db.wzj_contract_accessory a
		INNER JOIN wzj_db.wzj_file b ON a.file_id = b.id 
		WHERE a.contract_id = ?;`
	if err := db.Raw(sql, contractId).
		Find(&wzjContractAccessoryList).Error; err != nil {
		log.Error("GetContractAccessoryListByContractId--查询失败,失败原因：", err)
		return wzjContractAccessoryList, err
	}
	return wzjContractAccessoryList, nil
}
